﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Hkwl.WorldExpo.Merchant.Common;
using Hkwl.WorldExpo.Merchant.Model;
using Hkwl.WorldExpo.Merchant.Service;

namespace Hkwl.WorldExpo.Merchant.Web
{
    public partial class ClientReceiveDetail : BaseCheckPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataBind_ClientReceive(0);
            }
        }

        protected void DataBind_ClientReceive(int recordcount)
        {
            int clientId = int.Parse(Request.QueryString["ClientId"]);
            int merchantId = 0;
            if (Session["MerchantId"] != null)
            {
                merchantId = int.Parse(Session["MerchantId"].ToString());
                if (recordcount == 0)
                {
                    this.AspNetPager_Content.CurrentPageIndex = 1;
                }
                
                int count = recordcount;
                int pageIndex = this.AspNetPager_Content.CurrentPageIndex;
                int pageSize = this.AspNetPager_Content.PageSize;
                this.GridView_ClientReceive.DataSource = ServiceLocator.ILogService.GetSendLogCollection(merchantId, clientId, 1, 0, pageIndex, pageSize, ref count);
                this.GridView_ClientReceive.DataBind();
                this.AspNetPager_Content.RecordCount = count;
            }
            
        }

        protected void GridView_ClientReceive_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                NxSendLog sendLog = (NxSendLog)e.Row.DataItem;

                Label lbNum = (Label)e.Row.FindControl("lbNum");
                lbNum.Text = (e.Row.RowIndex + 1).ToString();

                Label lbProjectName = (Label)e.Row.FindControl("lbProjectName");
                lbProjectName.Text = ServiceLocator.IProjectService.GetNxProjectById(sendLog.ProjectId).ProjectName;

                Label lbSendTime = (Label)e.Row.FindControl("lbSendTime");
                lbSendTime.Text = sendLog.SendTime.ToString();

                Label lbUseTime = (Label)e.Row.FindControl("lbUseTime");
                lbUseTime.Text = sendLog.UseTime.ToString() == "0001-1-1 0:00:00" ? (String)GetGlobalResourceObject("Default","NOT_USED") : sendLog.UseTime.ToString();
            }
        }

        protected void AspNetPager_Content_PageChanged(object sender, EventArgs e)
        {
            DataBind_ClientReceive(this.AspNetPager_Content.RecordCount);
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("ClientStatistics.aspx");
        }
    }
}
